/* eslint-disable prefer-const */
/**
 * 该方法只能正确判定到2099年
/**
* 生肖构造函数，默认参数是当前日期
* @param {Number} year 年
* @param {Number} month 月
* @param {Number} day 日
*/
export class Zodiac {
  year: number
  month: number
  day: number
  constructor(year?: number, month?: number, day?: number) {
    const date = new Date()
    this.year = year ? year * 1 : date.getFullYear()
    this.month = month ? month * 1 : date.getMonth()
    this.day = day ? day * 1 : date.getDate()
  }
  /**
   * 获取C值
   * @return {Number} C
   */
  getC() {
    const _year = Math.floor(this.year / 100) + 1
    let C
    switch (_year) {
      case 20:
        C = 4.6295
        break
      case 21:
        C = 3.87
        break
      case 22:
        C = 4.15
        break
      default:
        C = 3.87
    }
    return C
  }
  /**
   * 获取立春日 一般都在2月
   * @return {Number} springDay
   */
  getSpringDay() {
    let Y = this.year % 100,
      D = 0.2422,
      C = this.getC(),
      // L = (Y - 1) / 4,
      springDay = 0
    springDay = Math.floor(Y * D + C) - Math.floor((Y - 1) / 4)
    return springDay
  }
  getZodiac() {
    let year = this.year,
      month = this.month,
      day = this.day,
      zodiac = ['鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪'],
      myPos = (year - 1900) % 12,
      myZodiac = zodiac[myPos],
      springDay = this.getSpringDay()

    switch (month) {
      case 1:
        let _myPos = myPos - 1
        if (_myPos < 0) {
          _myPos = 11
        }
        myZodiac = zodiac[_myPos]
        break
      case 2:
        if (day < springDay) {
          let _myPos = myPos - 1
          if (_myPos < 0) {
            _myPos = 11
          }
          myZodiac = zodiac[_myPos]
        }
        break
    }
    return myZodiac
  }
}
